package com.viphuli.app.tool.fragment;

import android.app.Activity;
import android.widget.TextView;
import android.widget.Toast;
import butterknife.Bind;
import butterknife.OnClick;

import com.loopj.android.http.RequestParams;
import com.offroader.utils.StringUtils;
import com.viphuli.app.tool.R;
import com.viphuli.app.tool.common.AccessTokenKeeper;
import com.viphuli.app.tool.common.MyPageHelper;
import com.viphuli.app.tool.http.ApiRequest;

/**
 * 登录
 * 
 * @author li.li
 *
 */
public class AccountBindPhoneFragment extends AccountVCodeFragment {

	@Bind(R.id.id_account_bind_phone_btn)
	protected TextView bindPhoneBtn;


	@Override
	protected int obtainContentRes() {
		return R.layout.frag_account_bind_phone;
	}

	@Override
	protected void initParams() {

	}

	@Override
	protected void initView() {

	}

	@Override
	protected void initData() {
	}

	/**
	 * 手机号绑定
	 */
	@OnClick(R.id.id_account_bind_phone_btn)
	public void bindPhone() {

		String phone = phoneText.getText().toString();
		String vCode = vcodeText.getText().toString();

		if (StringUtils.isBlank(phone)) {
			Toast.makeText(getActivity(), getString(R.string.tip_input_phone_number), Toast.LENGTH_SHORT).show();
			return;
		}

		if (StringUtils.isBlank(vCode)) {
			Toast.makeText(getActivity(), getString(R.string.tip_input_vcode), Toast.LENGTH_SHORT).show();
			return;
		}

		AccessTokenKeeper tokenKeeper = AccessTokenKeeper.readAccessToken(getActivity());

		if (tokenKeeper.isLogin()) {

			RequestParams params = new RequestParams();
			params.put("uid", tokenKeeper.getOpenId());
			params.put("phone_number", phone);
			params.put("v_code", vCode);

			ApiRequest.accountBindPhone.request(this, params);

		}

	}

	public TextView getBindPhoneBtn() {
		return bindPhoneBtn;
	}

	public static void go(Activity act, int resultCode) {
		MyPageHelper.accountBindPhone.showMyPage(act, resultCode);
	}


}
